//
//  UIColor+Extension.m
//  CSJExample
//
//  Created by ya on 12/5/16.
//  Copyright © 2016 ya. All rights reserved.
//

#import "UIColor+Extension.h"

@implementation UIColor (Extension)

+ (UIColor *)sj_randomColor {
    return [UIColor colorWithRed:(float)(arc4random() % 256) / 255.0 green:(float)(arc4random() % 256) / 255.0 blue:(float)(arc4random() % 256) / 255.0 alpha:1];
}

#pragma mark - 16进制颜色转换

+ (instancetype)sj_colorWithHex:(uint32_t)hex {

    int red = (hex & 0xFF0000) >> 16;   // (1 + 2) * 3
    int green = (hex & 0x00FF00) >> 8;
    int blue = hex & 0x0000FF;
    return [UIColor colorWithRed:red / 255.0f green:green / 255.0f blue:blue / 255.0f alpha:1];
}

#pragma mark - UIColor 获取 RGB 值
+ (NSDictionary *)sj_getRGBValueWithColor:(UIColor *)color {

    const CGFloat *components = CGColorGetComponents(color.CGColor);
    NSDictionary *dict = @{@"Red"   : @(components[0]),
                           @"Green" : @(components[1]),
                           @"Blue"  : @(components[2]),
                           @"Alpha" : @(components[3])};
    //    NSLog(@"Red:%f", components[0]);
    //    NSLog(@"Green:%f", components[1]);
    //    NSLog(@"Blue:%f", components[2]);
    //    NSLog(@"Alpha:%f", components[3]);
    return dict;
}

@end
